import Mock from 'mockjs';

function param2Obj(url) {
    const search = url.split('?')[1]
    if (!search) {
      return {}
    }
    return JSON.parse(
      '{"' +
      decodeURIComponent(search)
        .replace(/"/g, '\\"')
        .replace(/&/g, '","')
        .replace(/=/g, '":"') +
      '"}'
    )
  }

let List = [];

for (let i = 0; i < 100; i++) {
    List.push({
        time: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        state: Mock.Random.integer(0, 2)
    });
}

export default {
    getRunStatetData: config => {
        const { page = 1, limit = 20 } = param2Obj(config.url)
        const pageList = List.filter((item, index) => index < limit * page && index >= limit * (page - 1))
        return {
            code: 20000,
            count: List.length,
            list: pageList
        };
    }
};
